//
//  ReportProjectDeviceAlarmInfoCell.m
//  efairy
//
//  Created by 李锋 on 2019/3/21.
//  Copyright © 2019年 East. All rights reserved.
//

#import "ReportProjectDeviceAlarmInfoCell.h"

@implementation ReportProjectDeviceAlarmInfoCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self initView];
    }
    return self;
}



-(void)initView{
    
    _alarmType = [[UILabel alloc]init];//报警类型
    _alarmType.textColor = ColorFromRGB(0x666666);
    _alarmType.font = [UIFont systemFontOfSize:12.f];
    _alarmType.layer.borderColor = [ColorFromRGB(0xB3B8BE)CGColor];
    _alarmType.layer.borderWidth = 1.0f;
    _alarmType.textAlignment = NSTextAlignmentCenter;
    _alarmType.numberOfLines = 2;
    
    _alarmDates = [[UILabel alloc]init];  // 报警时间段
    _alarmDates.textColor = ColorFromRGB(0x666666);
    _alarmDates.font = [UIFont systemFontOfSize:12.f];
    _alarmDates.layer.borderColor = [ColorFromRGB(0xB3B8BE)CGColor];
    _alarmDates.layer.borderWidth = 1.0f;
    _alarmDates.textAlignment = NSTextAlignmentCenter;
    _alarmDates.numberOfLines = 2;
    
    _score = [[UILabel alloc]init];//峰值分数；
    _score.textColor = ColorFromRGB(0x666666);
    _score.font = [UIFont systemFontOfSize:12.f];
    _score.layer.borderColor = [ColorFromRGB(0xB3B8BE)CGColor];
    _score.layer.borderWidth = 1.0f;
    _score.textAlignment = NSTextAlignmentCenter;
    _score.numberOfLines = 2;
    
    _risk = [[UILabel alloc]init];//风险评估
    _risk.textColor = ColorFromRGB(0x666666);
    _risk.font = [UIFont systemFontOfSize:12.f];
    _risk.layer.borderColor = [ColorFromRGB(0xB3B8BE)CGColor];
    _risk.layer.borderWidth = 1.0f;
    _risk.textAlignment = NSTextAlignmentCenter;
    _risk.numberOfLines = 2;
    
    [self.contentView sd_addSubviews:@[_alarmType,_alarmDates,_score,_risk]];
    
    _alarmType.sd_layout.widthIs(44).heightIs(44).leftSpaceToView(self.contentView, -1)
    .topSpaceToView(self.contentView, -1);
    
    _alarmDates.sd_layout.widthIs((SCREEN_WIDTH-88)/2+10+4).heightIs(44).leftSpaceToView(_alarmType, -1)
    .topSpaceToView(self.contentView,-1);
    
    _score.sd_layout.widthIs((SCREEN_WIDTH-88)/2-10).heightIs(44).leftSpaceToView(_alarmDates, -1)
    .topSpaceToView(self.contentView,-1);
    
    _risk.sd_layout.widthIs(44).heightIs(44).leftSpaceToView(_score, -1)
    .topSpaceToView(self.contentView,-1);
    [self setupAutoHeightWithBottomView:_alarmType bottomMargin:0];
    
    
    
}
-(void)setDataModel:(ReportDeviceAlarmInfo *)data{
    if(data != nil){
        _alarmType.text = [NSString stringWithFormat:@"%@:\n%@",
                        [self getAlarmTypeName:(int)data.efairydevicealarmstatistics_alarm_type],
                        data.efairydevicealarmstatistics_pt_name];
        _alarmDates.text = [NSString stringWithFormat:@"%@~\n%@",data.efairydevicealarmstatistics_start_time,
                            data.efairydevicealarmstatistics_end_time];
        _score.text = data.efairydevicealarmstatistics_highest_score;
        if((int)data.risk_evaluation == 1){
            _risk.textColor = ColorFromRGB(0xFF0000);
        }else{
            _risk.textColor = ColorFromRGB(0x666666);
        }
        _risk.text = [self getRiskName:(int)data.risk_evaluation];
        
    }
}

-(NSString*)getAlarmTypeName:(int)type{
    if(type == 1){
        return @"报警";
    }else if(type == 2){
        return @"预警";
    }else if(type == 3){
         return @"故障";
    }
    return @"未知";
}

// 风险评估：1、高度危险，2、中度危险，3危险

-(NSString *)getRiskName:(int)type{
    if(type == 1) {
        return @"高度危险";
    } else if(type == 2) {
       return @"中度危险";
    } else if(type == 3) {
       return @"危险";
    }
    return @"高度危险";
}

@end
